package com.ruihu.admin.module.business.log.interfacelog.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruihu.admin.common.domain.PageResultDTO;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.module.business.log.interfacelog.dao.InterfaceLogDao;
import com.ruihu.admin.module.business.log.interfacelog.domain.dto.InterfaceLogAddDTO;
import com.ruihu.admin.module.business.log.interfacelog.domain.dto.InterfaceLogUpdateDTO;
import com.ruihu.admin.module.business.log.interfacelog.domain.dto.InterfaceLogQueryDTO;
import com.ruihu.admin.module.business.log.interfacelog.domain.entity.InterfaceLogEntity;
import com.ruihu.admin.module.business.log.interfacelog.domain.vo.InterfaceLogVO;
import com.ruihu.admin.module.business.log.interfacelog.domain.vo.InterfaceLogExcelVO;
import com.ruihu.admin.util.PageUtil;
import com.ruihu.admin.util.BeanUtil;
import com.ruihu.admin.util.RequestTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * [ 接口日志 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-09-16 00:33:38
 * @since JDK1.8
 */
@Service
public class InterfaceLogService {

    @Autowired
    private InterfaceLogDao interfaceLogDao;

    /**
     * 根据id查询
     */
    public InterfaceLogEntity getById(Long id){
        return  interfaceLogDao.selectById(id);
    }

    /**
     * 分页查询
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    public ResponseDTO<PageResultDTO<InterfaceLogVO>> queryByPage(InterfaceLogQueryDTO queryDTO) {
        Page page = PageUtil.convert2QueryPage(queryDTO);
        List<InterfaceLogVO> voList = interfaceLogDao.queryByPage(page, queryDTO);
        page.setRecords(voList);
        PageResultDTO<InterfaceLogVO> pageResultDTO = PageUtil.convert2PageResult(page);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    public ResponseDTO<String> add(InterfaceLogAddDTO addDTO) {
        InterfaceLogEntity entity = BeanUtil.copy(addDTO, InterfaceLogEntity.class);
        interfaceLogDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(InterfaceLogUpdateDTO updateDTO) {
        InterfaceLogEntity entity = BeanUtil.copy(updateDTO, InterfaceLogEntity.class);
        interfaceLogDao.updateById(entity);
        return ResponseDTO.succ();
    }

    public ResponseDTO<String> update(InterfaceLogEntity interfaceLogEntity) {
        interfaceLogEntity.setUpdateTime(new Date());
        this.interfaceLogDao.updateById(interfaceLogEntity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        interfaceLogDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    public List<InterfaceLogExcelVO> queryAllExportData(InterfaceLogQueryDTO queryDTO) {
        return interfaceLogDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author Tony
     * @date 2022-09-16 00:33:38
     */
    public List<InterfaceLogExcelVO> queryBatchExportData(List<Long> idList) {
        return interfaceLogDao.queryBatchExportData(idList);
    }
}
